package com.sskj.mine.invite;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.widget.TextView;

import com.github.tifezh.kchartlib.chart.formatter.TimeFormatter;
import com.sskj.common.adapter.slimadapter.IViewInjector;
import com.sskj.common.adapter.slimadapter.SlimAdapter;
import com.sskj.common.adapter.slimadapter.SlimInjector;
import com.sskj.common.base.App;
import com.sskj.common.box.decoration.DividerLineItemDecoration;
import com.sskj.lib.base.BaseActivity;
import com.sskj.lib.util.TimeFormatUtil;
import com.sskj.mine.R;
import com.sskj.mine.R2;
import com.sskj.mine.account.data.AccountBean;
import com.sskj.mine.bean.InvireTeamRecord;
import com.sskj.mine.bean.InviteRecord;
import com.sskj.mine.bean.MineInviteBean;


import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @author Hey
 * Create at  2019/05/03
 */
public class TeamActivity extends BaseActivity<TeamPresenter> {

    @BindView(R2.id.reward_tv)
    TextView rewardTv;
    @BindView(R2.id.reward_total_tv)
    TextView rewardTotalTv;
    @BindView(R2.id.list)
    RecyclerView list;
    private SlimAdapter adapter;

    @Override
    public int getLayoutId() {
        return R.layout.mine_activity_team;
    }

    @Override
    public TeamPresenter getPresenter() {
        return new TeamPresenter();
    }

    @Override
    public void initView() {
        setTitle(App.INSTANCE.getString(R.string.mine_teamActivity1_j));
        list.setLayoutManager(new LinearLayoutManager(this));
        list.addItemDecoration(new DividerLineItemDecoration(this)
                .setFirstDraw(false)
                .setLastDraw(false)
                .setDividerColor(color(R.color.mine_divider)));
        adapter = SlimAdapter.create().register(R.layout.mine_team_layout, new SlimInjector<MineInviteBean.MineBean>() {
            @Override
            public void onInject(MineInviteBean.MineBean inviteList, IViewInjector iViewInjector, List<Object> list) {
                iViewInjector.text(R.id.id, inviteList.getRealname())
                        .text(R.id.center, TextUtils.isEmpty(inviteList.getMobile()) ? inviteList.getMail() : inviteList.getMobile())
                        .text(R.id.right, TimeFormatUtil.SF_FORMAT_E.format(Double.valueOf(inviteList.getReg_time()) * 1000));
            }
        }).attachTo(list);
    }

    @Override
    public void initData() {
        mPresenter.getRecord();
    }

    public static void start(Context context) {
        Intent intent = new Intent(context, TeamActivity.class);
        context.startActivity(intent);
    }

    public void updateUi(MineInviteBean record) {
        adapter.updateData(record.getList());
    }

}
